package net.NingXiaRuiTai.ShortChain.Manager.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.NingXiaRuiTai.ShortChain.Manager.LinkGroupManager;
import net.NingXiaRuiTai.ShortChain.mapper.LinkGroupMapper;
import net.NingXiaRuiTai.ShortChain.model.LinkGroupDO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class LinkGroupManagerImpl implements LinkGroupManager {
    @Resource
    private LinkGroupMapper linkGroupMapper;
    @Override
    public int add(LinkGroupDO linkGroupDO) {

        return  linkGroupMapper.insert(linkGroupDO);
    }

    @Override
    //删除分组，实际的删除，应该是逻辑删除才行 TODO
    // 所以这里的删除，应该是修改状态为删除
    public int del(Long id, long accountNo) {
        return linkGroupMapper.delete(new QueryWrapper<LinkGroupDO>().eq("id",id).eq("account_no",accountNo));
    }

    @Override
    public LinkGroupDO detail(Long groupId, long accountNo) {

        return linkGroupMapper.selectOne(new QueryWrapper<LinkGroupDO>().eq("id",groupId).eq("account_no",accountNo));
    }

    @Override
    public List<LinkGroupDO> listAllGroup(Long accountNo) {
        return linkGroupMapper.selectList(new QueryWrapper<LinkGroupDO>().eq("account_no",accountNo));

    }

    @Override
    public int updateById(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.update(linkGroupDO,new QueryWrapper<LinkGroupDO>().eq("id",linkGroupDO.getId()).eq("account_no",linkGroupDO.getAccountNo()));
    }
}
